package com.zwj.controller;


import com.zwj.bo.BatchBo;
import com.zwj.bo.CourseInfoBo;
import com.zwj.bo.InsertBatchCourseBo;
import com.zwj.dto.Result;
import com.zwj.entity.BatchEntity;
import com.zwj.entity.CourseInfoEntity;
import com.zwj.service.BatchService;
import com.zwj.service.CourseInfoService;
import com.zwj.utils.TokenUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zwj
 * @since 2021-11-04
 */
@Api(value = "批次管理",tags="批次管理")
@RestController
@RequestMapping("/batch-entity")
public class BatchController {
    private final BatchService batchService;

    public BatchController(BatchService batchService) {
        this.batchService = batchService;
    }

    @ApiOperation(value = "条件查询批次", notes = "条件查询批次")
    @PostMapping("/selectBatch")
    public Result selectBatch(@RequestBody BatchBo batchBo) {
        return batchService.selectBatch(batchBo);
    }

    @ApiOperation(value = "添加批次", notes = "添加批次")
    @PostMapping("/addBatch")
    public Result addBatch(@RequestBody BatchBo batchBo, HttpServletRequest httpServletRequest) {
        String userId = TokenUtils.getUserID(httpServletRequest);
        return batchService.addBatch(batchBo,userId);
    }

    @ApiOperation(value = "修改批次状态", notes = "修改批次状态")
    @PostMapping("/updateBatchStatus")
    public Result updateBatchStatus(@RequestBody BatchEntity batchEntity) {
        return batchService.updateBatchStatus(batchEntity);
    }

    @ApiOperation(value = "修改批次信息", notes = "修改批次信息")
    @PostMapping("/updateBatch")
    public Result updateBatch(@RequestBody BatchEntity batchEntity, HttpServletRequest httpServletRequest) {
        String userId = TokenUtils.getUserID(httpServletRequest);
        return batchService.updateBatch(batchEntity,userId);
    }

    @ApiOperation(value = "删除批次", notes = "删除批次")
    @PostMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody BatchBo batchBo) {
        return batchService.deleteBatch(batchBo);
    }

    //批量
    @ApiOperation(value = "批量",notes = "批量")
    @PostMapping("/insert")
    public Result insert(@RequestBody(required = false) InsertBatchCourseBo insertBatchCourseBo){
        return batchService.insert(insertBatchCourseBo);
    }

}